<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html style="height: 100%">
<head>

    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
</head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<body style="overflow-y: auto; height: 100%; ">

<jsp:include page="teacher_header.jsp"/>
<hr>
<div class="container" style="height: 100%">

    <label class="col-sm-2 control-label">以下是您的信息：</label>
    <hr>
    <form class="form-horizontal" id="add">
        <div class="form-group">
            <label class="col-sm-2 control-label">教师名称</label>
            <div class="col-sm-10">
                <input type="text" name="teachername" class="form-control" id="teacherName_input"
                       placeholder="teacherName">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">教师身份证号</label>
            <div class="col-sm-10">
                <input type="text" name="teacheridenticard" class="form-control" id="teacherIdentiCard_input"
                       placeholder="teacherIdentiCard">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">教师性别</label>
            <div class="col-sm-10">
                <label class="radio-inline">
                    <input type="radio" name="teachersex" id="teacherSex1_input" value="1" checked="checked"> 女
                </label>
                <label class="radio-inline">
                    <input type="radio" name="teachersex" id="ieacherSex2_input" value="2"> 男
                </label>
            </div>

        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">教师生日</label>
            <div class="col-sm-10">
                <input type="text" name="teacherbirth" class="form-control" id="teacherBirth_input"
                       placeholder="xxxx-xx-xx">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">政治面貌</label>
            <div class="col-sm-10">
                <select class="form-control" name="teacherparty" id="teacherParty_input">
                    <option value="1">群众</option>
                    <option value="2">中共党员</option>
                    <option value="3">民革党员</option>
                    <option value="4">民盟党员</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">入教学历</label>
            <div class="col-sm-10">
                <select class="form-control" name="teacherstudy" id="teacherStudy_input">
                    <option value="1">研究生硕士</option>
                    <option value="2">博士研究生</option>
                    <option value="3">其他</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">住址</label>
            <div class="col-sm-10">
                <input type="text" name="teacheraddress" class="form-control" id="teacherAddress_input"
                       placeholder="teacherAddress">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">职称</label>
            <div class="col-sm-10">
                <select class="form-control" name="teacheracademic" id="teacherAcademic_input">
                    <option value="1">讲师</option>
                    <option value="2">副教授</option>
                    <option value="3">教授</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">联系方式</label>
            <div class="col-sm-10">
                <input type="text" name="teacherphone" class="form-control" id="teacherPhone_input"
                       placeholder="teacherPhone">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">入职时间</label>
            <div class="col-sm-10">
                <input type="text" name="teacherintime" class="form-control" id="teacherInTime_input"
                       placeholder="xxxx-xx-xx">
            </div>
        </div>
    </form>
    <div class="col-md-4 col-md-offset-5">
        <button class="btn btn-success btn-lg " id="sub-btn">更改</button>
    </div>
</div>

<div id="footer" class="text-center" style="position: absolute;width:100%">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <hr style="height:3px; background-color: #000000;"/>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    $.ajax({
        url: "${APP_PATH}/getTeacherInfor",
        type: "POST",
        data: $("#add").serialize(),
        success: function (result) {
            showData(result);
        }
    });

    //查询出来的结果显示在输入框中
    function showData(result) {
        var data = result.data;
        var obj = JSON.parse(JSON.stringify(data)) //val为解析出来的对象


        $("#teacherName_input").val(obj.teachername);
        $("#teacherIdentiCard_input").val(obj.teacheridenticard);
        if (obj.teachersex == 1) {
            $("input[name='teachersex'][value=1]").attr("checked", true);
        } else {
            $("input[name='teachersex'][value=2]").attr("checked", true);
        }
        $("#teacherBirth_input").val(obj.teacherbirth);
        $("#teacherParty_input").val(obj.teacherparty);
        $("#teacherStudy_input").val(obj.teacherstudy);
        $("#teacherAddress_input").val(obj.teacheraddress);
        $("#teacherAcademic_input").val(obj.teacheracademic);
        $("#teacherPhone_input").val(obj.teacherphone);
        $("#teacherInTime_input").val(obj.teacherintime);
    }

    $("#sub-btn").click(function () {
        $.ajax({
            url: "${APP_PATH}/updateTeacherInfor",
            type: "POST",
            data: $("#add").serialize(),
            success: function (result) {
                alert(result.message);
            }
        });
    });
</script>

</body>
</html>
